import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// import dataV from '@jiaminghi/data-view';
import DataVVue3 from '@kjgl77/datav-vue3'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import $ from 'jquery'
// import scroll from 'vue-seamless-scroll'

// 引入全局css
import './assets/scss/style.scss';
// 引入图表（所有图标见 icon 目录下的 demo_index.html）
import './assets/icon/iconfont.css'
// 引入 全局注册组件
import PublicComponent from '@/components/componentInstall';
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import storage from '@/store'
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.use(ElementPlus, {
  locale: zhCn,
})
// app.use(scroll,{componentName: 'scroll-seamless'})
app.use(PublicComponent)
// app.use(dataV)
app.use(DataVVue3)
app.use(store)
app.use(router)
app.use($)
app.mount('#app')

router.beforeEach((to, from, next) => {
  const rk=storage.state.userInfo.rk
  if(!rk){
    if( to.path === '/user/subPage'){
      console.log('tottototo',to)
      if(JSON.stringify(to.query) === '{}'){
        next('/user/login')
        return
      }else{
        if(to.query.hasOwnProperty('authToken')){
          next()
          return
        }else{
          next('/user/login')
          return
        }
      }
    }
    if( to.path === '/user/login'){
      next()
      return
    }
    
    next('/user/login')
  }else{
    next()
  }
})
